package jsyf.oa.dao.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.com.dao.BaseJdbcDao;
import jsyf.oa.entity.system.RoleNameEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Lenovo on 2017/12/7.
 */
@Repository
public class RoleNameDao extends BaseDao {

    public RoleNameDao() {
        super.iBaseEntity = new RoleNameEntity();
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return  JSON.toJavaObject(json, RoleNameEntity.class);
    }

    public RoleNameEntity getEntityById(String id){
        return (RoleNameEntity) super.getIBaseEntityById(id);
    }

    public Boolean sort(String roleNameIds){
        List<String> list = BaseJdbcDao.stringToList(roleNameIds);
        for (int i = 0; i < list.size(); i++) {
            JSONObject obj = new JSONObject();
            obj.put("ID",list.get(i));
            obj.put("SORT_NO",i);

            JSONObject objId = new JSONObject();
            objId.put("ID",list.get(i));
            super.update(iBaseEntity.getTableName(),obj,objId);
        }
        return true;
    }
}
